package com.liz.test_old;

import java.math.BigDecimal;
import java.sql.*;

public class Text1_query {
    public static void main(String[] args)  {
        String jdbcdrive = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/bylianxi";
        String username = "root";
        String userpassword = "Au7989l";
        Connection conn = null;
        Statement statement = null;
        ResultSet set = null;
        try {
            Class.forName(jdbcdrive);
            conn = DriverManager.getConnection(url,username,userpassword);
            String sql = "select empno,ename,sal from emp";
            statement = conn.createStatement();
            set = statement.executeQuery(sql);
            while(set.next()){
                int empno = set.getInt("empno");
                String ename = set.getString("ename");
                BigDecimal sal = set.getBigDecimal("sal");
                System.out.println(empno+"--"+ename+"--"+sal);
            }
//            System.out.println(conn);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
            try {
                set.close();
                statement.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }


        }
    }
}
